% Generator: GNU source-highlight, by Lorenzo Bettini, http://www.gnu.org/software/src-highlite

{\ttfamily \raggedright {
\noindent
\mbox{}\textit{\textcolor{Brown}{/*}} \\
\mbox{}\textit{\textcolor{Brown}{\ \ Returns\ positive\ if\ a-b-c\ make\ a\ left\ turn.}} \\
\mbox{}\textit{\textcolor{Brown}{\ \ Returns\ negative\ if\ a-b-c\ make\ a\ right\ turn.}} \\
\mbox{}\textit{\textcolor{Brown}{\ \ Returns\ 0.0\ if\ a-b-c\ are\ colineal.}} \\
\mbox{}\textit{\textcolor{Brown}{\ */}} \\
\mbox{}\textcolor{ForestGreen}{double}\ \textbf{\textcolor{Black}{turn}}\textcolor{BrickRed}{(}\textbf{\textcolor{Blue}{const}}\ point\ \textcolor{BrickRed}{\&}a\textcolor{BrickRed}{,}\ \textbf{\textcolor{Blue}{const}}\ point\ \textcolor{BrickRed}{\&}b\textcolor{BrickRed}{,}\ \textbf{\textcolor{Blue}{const}}\ point\ \textcolor{BrickRed}{\&}c\textcolor{BrickRed}{)}\textcolor{Red}{\{} \\
\mbox{}\ \ \textcolor{ForestGreen}{double}\ z\ \textcolor{BrickRed}{=}\ \textcolor{BrickRed}{(}b\textcolor{BrickRed}{.}x\ \textcolor{BrickRed}{-}\ a\textcolor{BrickRed}{.}x\textcolor{BrickRed}{)*(}c\textcolor{BrickRed}{.}y\ \textcolor{BrickRed}{-}\ a\textcolor{BrickRed}{.}y\textcolor{BrickRed}{)}\ \textcolor{BrickRed}{-}\ \textcolor{BrickRed}{(}b\textcolor{BrickRed}{.}y\ \textcolor{BrickRed}{-}\ a\textcolor{BrickRed}{.}y\textcolor{BrickRed}{)*(}c\textcolor{BrickRed}{.}x\ \textcolor{BrickRed}{-}\ a\textcolor{BrickRed}{.}x\textcolor{BrickRed}{);} \\
\mbox{}\ \ \textbf{\textcolor{Blue}{if}}\ \textcolor{BrickRed}{(}\textbf{\textcolor{Black}{fabs}}\textcolor{BrickRed}{(}z\textcolor{BrickRed}{)}\ \textcolor{BrickRed}{$<$}\ \textcolor{Purple}{1e-9}\textcolor{BrickRed}{)}\ \textbf{\textcolor{Blue}{return}}\ \textcolor{Purple}{0.0}\textcolor{BrickRed}{;} \\
\mbox{}\ \ \textbf{\textcolor{Blue}{return}}\ z\textcolor{BrickRed}{;} \\
\mbox{}\textcolor{Red}{\}} \\
\mbox{} \\
\mbox{}\textit{\textcolor{Brown}{/*}} \\
\mbox{}\textit{\textcolor{Brown}{\ \ Returns\ true\ if\ polygon\ p\ is\ convex.}} \\
\mbox{}\textit{\textcolor{Brown}{\ \ False\ if\ it's\ concave\ or\ it\ can't\ be\ determined}} \\
\mbox{}\textit{\textcolor{Brown}{\ \ (For\ example,\ if\ all\ points\ are\ colineal\ we\ can't\ }} \\
\mbox{}\textit{\textcolor{Brown}{\ \ make\ a\ choice).}} \\
\mbox{}\textit{\textcolor{Brown}{\ */}} \\
\mbox{}\textcolor{ForestGreen}{bool}\ \textbf{\textcolor{Black}{isConvexPolygon}}\textcolor{BrickRed}{(}\textbf{\textcolor{Blue}{const}}\ vector\textcolor{BrickRed}{$<$}point\textcolor{BrickRed}{$>$}\ \textcolor{BrickRed}{\&}p\textcolor{BrickRed}{)}\textcolor{Red}{\{} \\
\mbox{}\ \ \textcolor{ForestGreen}{int}\ mask\ \textcolor{BrickRed}{=}\ \textcolor{Purple}{0}\textcolor{BrickRed}{;} \\
\mbox{}\ \ \textcolor{ForestGreen}{int}\ n\ \textcolor{BrickRed}{=}\ p\textcolor{BrickRed}{.}\textbf{\textcolor{Black}{size}}\textcolor{BrickRed}{();} \\
\mbox{}\ \ \textbf{\textcolor{Blue}{for}}\ \textcolor{BrickRed}{(}\textcolor{ForestGreen}{int}\ i\textcolor{BrickRed}{=}\textcolor{Purple}{0}\textcolor{BrickRed}{;}\ i\textcolor{BrickRed}{$<$}n\textcolor{BrickRed}{;}\ \textcolor{BrickRed}{++}i\textcolor{BrickRed}{)}\textcolor{Red}{\{} \\
\mbox{}\ \ \ \ \textcolor{ForestGreen}{int}\ j\textcolor{BrickRed}{=(}i\textcolor{BrickRed}{+}\textcolor{Purple}{1}\textcolor{BrickRed}{)\%}n\textcolor{BrickRed}{;} \\
\mbox{}\ \ \ \ \textcolor{ForestGreen}{int}\ k\textcolor{BrickRed}{=(}i\textcolor{BrickRed}{+}\textcolor{Purple}{2}\textcolor{BrickRed}{)\%}n\textcolor{BrickRed}{;} \\
\mbox{}\ \ \ \ \textcolor{ForestGreen}{double}\ z\ \textcolor{BrickRed}{=}\ \textbf{\textcolor{Black}{turn}}\textcolor{BrickRed}{(}p\textcolor{BrickRed}{[}i\textcolor{BrickRed}{],}\ p\textcolor{BrickRed}{[}j\textcolor{BrickRed}{],}\ p\textcolor{BrickRed}{[}k\textcolor{BrickRed}{]);} \\
\mbox{}\ \ \ \ \textbf{\textcolor{Blue}{if}}\ \textcolor{BrickRed}{(}z\ \textcolor{BrickRed}{$<$}\ \textcolor{Purple}{0.0}\textcolor{BrickRed}{)}\textcolor{Red}{\{} \\
\mbox{}\ \ \ \ \ \ mask\ \textcolor{BrickRed}{$|$=}\ \textcolor{Purple}{1}\textcolor{BrickRed}{;} \\
\mbox{}\ \ \ \ \textcolor{Red}{\}}\textbf{\textcolor{Blue}{else}}\ \textbf{\textcolor{Blue}{if}}\ \textcolor{BrickRed}{(}z\ \textcolor{BrickRed}{$>$}\ \textcolor{Purple}{0.0}\textcolor{BrickRed}{)}\textcolor{Red}{\{} \\
\mbox{}\ \ \ \ \ \ mask\ \textcolor{BrickRed}{$|$=}\ \textcolor{Purple}{2}\textcolor{BrickRed}{;} \\
\mbox{}\ \ \ \ \textcolor{Red}{\}} \\
\mbox{}\ \ \ \ \textbf{\textcolor{Blue}{if}}\ \textcolor{BrickRed}{(}mask\ \textcolor{BrickRed}{==}\ \textcolor{Purple}{3}\textcolor{BrickRed}{)}\ \textbf{\textcolor{Blue}{return}}\ \textbf{\textcolor{Blue}{false}}\textcolor{BrickRed}{;} \\
\mbox{}\ \ \textcolor{Red}{\}} \\
\mbox{}\ \ \textbf{\textcolor{Blue}{return}}\ mask\ \textcolor{BrickRed}{!=}\ \textcolor{Purple}{0}\textcolor{BrickRed}{;} \\
\mbox{}\textcolor{Red}{\}} \\

} \normalfont\normalsize
